//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;

namespace CommunityServer.Blogs.Controls
{
	/// <summary>
	/// Summary description for DisplayUserWelcome.
	/// </summary>
	public class DisplayUserWelcome : WeblogThemedControl
	{
		#region member varaibles
		CSContext csContext = CSContext.Current;
		#endregion

		protected override void AttachChildControls()
		{
			int privateMessageCount = 0;
			string url = "";

			// Only process if the user is signed in
			if (!csContext.Context.Request.IsAuthenticated)
				return;

			Control privateMessages = FindControl("PrivateMessages");
			if (privateMessages != null)
			{
                if(Users.EnablePM(csContext.User))
                {
                    privateMessageCount = UserMessages.UnreadMessagesCount( csContext.User.UserID );
                    if (privateMessageCount > 0) 
                    {
                        url = string.Format(ResourceManager.GetString("PrivateMessage_Unread"), privateMessageCount);
                    } 
                    else 
                    {
                        url = string.Format(ResourceManager.GetString("PrivateMessages_Messages"), privateMessageCount);
                    }

                    // Set URL
		
                    url = "<a href=\"" + Globals.GetSiteUrls().UserPrivateMessages + "\">" + url + "</a>";

                    // Add to control tree
                    privateMessages.Controls.Add(new LiteralControl( " | " + url));
                }
                else
                {
                    privateMessages.Visible = false;
                }
			}
		}

	}
}
